#!/bin/sh

APP=zotero
SITE="https://www.zotero.org"

# CREATE THE DIRECTORY
mkdir -p /opt/"$APP"
cd /opt/"$APP"

# ADD THE REMOVER
echo '#!/bin/sh' >> /opt/"$APP"/remove
echo "rm -R -f  /opt/$APP /usr/local/share/applications/$APP-AM.desktop /usr/local/bin/$APP" >> /opt/"$APP"/remove
chmod a+x /opt/"$APP"/remove

# DOWNLOAD THE ARCHIVE
mkdir -p tmp
cd ./tmp

wget "https://www.zotero.org/download/client/dl?channel=release&platform=linux-x86_64" --trust-server-names

[ -e ./*tar.* ] && tar fx ./*tar.* && rm -f ./*tar.*
cd ..
mv ./tmp/Zotero_linux-x86_64/* ./
rm -R -f ./tmp

# LINK TO PATH
ln -s "/opt/$APP/$APP" "/usr/local/bin/$APP"

# LAUNCHER
echo "[Desktop Entry]
Name=Zotero
Exec=$APP
Icon=/opt/$APP/icons/icon128.png
Type=Application
Terminal=false
Categories=Office;
MimeType=text/plain;x-scheme-handler/zotero;application/x-research-info-systems;text/x-research-info-systems;text/ris;application/x-endnote-refer;application/x-inst-for-Scientific-info;application/mods+xml;application/rdf+xml;application/x-bibtex;text/x-bibtex;application/marc;application/vnd.citationstyles.style+xml
X-GNOME-SingleWindow=true"  > /usr/local/share/applications/"$APP"-AM.desktop
